package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.GuildMember;
import com.xcity.db.entity.Player;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.formation.Formation;
import com.xcity.game.guild.GuildService;
import com.xcity.game.player.cache.PlayerCacheService;

import naga.x.App;
import naga.x.game.time.TimeUpdater;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;
import naga.x.util.TimeUtils;

@PomeloMessage(type = Message.Type.RESPONSE)
public class GuildMemberListResponse extends Response {

	private List<GuildMemberSimpleInfo> list;
	
	public static class GuildMemberSimpleInfo{
		public long id;
		public String name;
		public int level;
		public int isOnline;
		public long time;//上次登出时间
		public int fightValue;
		public int duty;//成员职位 0普通 1管理 2会长
		public String icon;//头像
		
		public GuildMemberSimpleInfo(GuildMember member, Player player){
			id = member.getId();
			duty = GuildService.getClientDuty(member.getDuty());
			name = player.getName();
			level = player.getLevel();
			isOnline = player.isOnline()? 1: 0;
			time = player.getLastLogoutTime() != null?player.getLastLogoutTime().getTime() : player.getCreateTime().getTime();
			fightValue = CombatUtils.getCombatPower(player, player.getFormations().get(Formation.TYPE_NORMAL).getUnits());//CombatUtils.calcCombatPower(player);
			icon = player.getIcon();
		}
	}
	public GuildMemberListResponse(int serial, List<GuildMember> memberList) {
		super(serial);
		PlayerCacheService pcs = App.getApp().getServiceManager().get(PlayerCacheService.class);
		list = new ArrayList<GuildMemberSimpleInfo>();
		for(int i = 0;i < memberList.size(); i++){
			GuildMember member = memberList.get(i);
			Player player = pcs.find(member.getId());
			if(player != null){
				list.add(new GuildMemberSimpleInfo(member, player));
			}
		}
	}
	public List<GuildMemberSimpleInfo> getList() {
		return list;
	}
	public void setList(List<GuildMemberSimpleInfo> list) {
		this.list = list;
	}
}
